import copy


# 初始图书馆藏
library_books = [
    {
        # 书名
        "title": "Python Programming",
        # 作者
        "author": "John Doe",
        # 图书 id
        "id": 101,
        # 是否可借
        "available": True
    },
    {
        "title": "Data Science Basics",
        "author": "Jane Smith",
        "id": 102,
        "available": True
    },
    {
        "title": "Machine Learning",
        "author": "Alice Brown",
        "id": 103,
        "available": True
    }
]

# 深浅拷贝
b_book_1 = copy.copy(library_books[0])
b_book_2 = copy.deepcopy(library_books[1])
borrow_books = [b_book_1, b_book_2]

library_books[1] = {
  "title": "Data Science Basics",
          "author": "Jane Smith",
          "id": 602,
          "available": True
    }

print(library_books)
print(borrow_books)

# 借阅
def borrow_book(book_title):
  for lb in library_books:
    # 判断是否有这本书
    if lb.get("title") == book_title:
      print("馆藏中有这本书")
      if lb.get("available"):
        print(f"{book_title}可借阅~")
        return
      else:
        print(f"{book_title}不可借阅！")
        return
    else:
      continue
  print("没有这本书！")
  return


# 检查某本书是否在借阅列表中，结合成员运算符。
def in_borrow_list(book_title):
  for b in borrow_books:
    if book_title in b.keys() :
      print(f"{book_title}这本书在借阅列表里")
      return
    else:
      continue
  print(f"{book_title}这本书不在借阅列表里")
  return


# 判断是否为同一本书
def is_same():
  for lb in library_books:
    # 使用身份运算符 is 和 is not 比较对象是否为同一本书。
    for b in borrow_books:
      if b.get("title") == lb.get("title"):
        if b is lb:
          print(f"借阅列表中的{b.get('title')}与图书列表中的{lb.get('title')}是同一本")
        else:
          print(f"借阅列表中的{b.get('title')}与图书列表中的{lb.get('title')}不是同一本")



if __name__ == '__main__':
    borrow_book("Data Science Basics")
    borrow_book("Pg")
    in_borrow_list("Python Programming")
    in_borrow_list("Machine Learning")
    is_same()


















